// 全局默认配置层
export const globalButtonConfig = {
  // 基础属性默认值
  defaults: {
    code: 'default' as const,
    type: 'primary' as const,
    size: 'default' as const,
    disabled: false,
    loading: false,
  },

  // 按 code 映射的默认图标
  icons: {
    add: 'ep:plus',
    edit: 'ep:edit',
    delete: 'ep:delete',
    view: 'ep:view',
    append: 'ep:circle-plus',
    _fallback: 'mdi:help-circle', // 兜底图标
  },

  // 按 code 映射的默认文本
  texts: {
    add: '新增',
    edit: '编辑',
    delete: '删除',
    view: '详情',
    _fallback: '未知操作',
  },
} as const;

// 步骤 1 - 定义类型守卫
const isValidIconCode = (
  code: string,
): code is keyof typeof globalButtonConfig.icons => {
  return code in globalButtonConfig.icons;
};
// 步骤 2 - 安全访问
export const getIcon = (code: string) => {
  return isValidIconCode(code)
    ? globalButtonConfig.icons[code]
    : globalButtonConfig.icons._fallback;
};

// 步骤 1 - 定义类型守卫
const isValidTextCode = (
  code: string,
): code is keyof typeof globalButtonConfig.texts => {
  return code in globalButtonConfig.texts;
};
// 步骤 2 - 安全访问
export const getTitle = (code: string) => {
  return isValidTextCode(code)
    ? globalButtonConfig.texts[code]
    : globalButtonConfig.texts._fallback;
};
